<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<link rel="stylesheet" href="../../../static/font-awesome-4.7.0/css/font-awesome.min.css">
	<link rel="stylesheet" href="../../../static/vui/css/vui.css">

	<script type="text/javascript" src="../../../static/js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="../../../static/js/jquery.cookie.min.js"></script>
	<script type="text/javascript" src="../../../static/layer/layer.js"></script>
	<script type="text/javascript" src="../../../static/laydate/laydate.js"></script>
	<script type="text/javascript" src="../../../static/vui/js/vui.js"></script>
	<script type="text/javascript" src="../../../static/vui/js/datagrid.js"></script>
	<script type="text/javascript" src="../../../static/js/common.js"></script>
</head>
<body>

<div id="formArea">
	<table class="table-top">
		<tr>
			<td>
				<label>客户</label>
			</td>
			<td>
				<div id="relationId"></div>
			</td>
			<td>
				<label>单据编号</label>
			</td>
			<td>
				<input type="text" class="input input-query" name="code" autocomplete="off"/>
			</td>
			<td>
				<label class="label">单据日期</label>
			</td>
			<td>
				<input type="text" n="date" class="input search-date" name="dateStart" autocomplete="off"/>&nbsp;-&nbsp;
				<input type="text" n="date" class="input search-date" name="dateEnd" autocomplete="off"/>
			</td>
			<td>
				<label>单据状态</label>
			</td>
			<td>
				<div id="statusId"></div>
			</td>
			<td>
				<button class="button" id="query"><span>查询</span></button>
				<button class="button" id="create"><span>新增</span></button>
			</td>
		</tr>
	</table>
</div>
</fieldset>
<div id="table"></div>

<script>
	var orderType = 20;
    $(function(){
        $('#create').click(function(){
            location.href = 'market_add.html';
        });

        $('#relationId').search({
            name:'relationId',
            click:function () {
                app.window(layer,{
                    title:'客户选择',
                    btn:[],
                    area: ['860px', '600px'],
                    content: '../../common/customer_list.html?index=-1&queryId=relationId'
                });
            }
        });

        $('#query').click(function(){
            var queryParams = app.serializeForm();
            queryParams.orderType = orderType;
            queryParams.code = deletePrefix(queryParams.code);
            vui.datagrid("reload","#table",queryParams);
        });

        var nowDate = app.time2str(new Date());

        var dateStart = laydate.render({
            elem: 'input[name="dateStart"]',value:nowDate.substr(0,8)+'01',max:nowDate,
            done: function(value,date){
                if(value){
                    date.month=date.month-1;
                    dateEnd.config.min = date;
                }else{
                    dateEnd.config.min=dateStart.config.min;
                }
            }
        });
        var dateEnd = laydate.render({
            elem: 'input[name="dateEnd"]',value:nowDate,min:nowDate.substr(0,8)+'01',
            done: function(value,date){
                if(value){
                    date.month=date.month-1;
                    dateStart.config.max = date;
                }else{
                    dateStart.config.max=dateEnd.config.max;
                }
            }
        });

        var type = [{"value":app.DEFAULT_ALL_VALUE,"text":"全部状态"},{"value":1,"text":"未审核"},{"value":20,"text":"未出单"},{"value":21,"text":"部分出单"},{"value":22,"text":"已出单"}];
        $('#statusId').combobox({
            width:100,
            data:type,
            name:'status'
        });

        $('#table').datagrid({
            firstLoad:true,
            url:app.BASE_API_URL+'order/page',
            queryParams:{orderType:orderType},
            columns:[
                {field:'date',title:'单据日期',width:100,fixed:true,formatter:app.timeFormatter},
                {field:'code',title:'单据编号',width:160,fixed:true,formatter:function (row) {
                        return '<a class="a" href="./market_add.html?id='+row.id+'">XD'+row.code+'</a>';
                    }},
                {field:'bussType',title:'业务类型',fixed:true,width:80,formatter:function (row) {
                        return row.bussType == 1 ? app.getLable('售货','success'): app.getLable('退货','warning');
                    }},
                {field:'relationName',title:'供应商',fixed:true,width:160},
                {field:'dueMoney',title:'订单金额',width:100,fixed:true,n:'money'},
                {field:'num',title:'商品数量',width:80,fixed:true,n:'number'},
                {field:'discountMoney',title:'优惠金额',width:100,fixed:true,n:'money'},
                {field:'realMoney',title:'应收金额',width:100,fixed:true,n:'money',formatter:function (row) {
                        return row.dueMoney;
                        return app.div(app.sub(row.dueMoney,row.discountMoney),1);
                    }},
                {field:'status',title:'单据状态',width:80,fixed:true,formatter:function (row) {
                        var txt = row.bussType == 1 ?'出':'入';
                        if( row.status == '1' ){
                            return app.getLable('未审核','success');
                        }else if( row.status == '20' ){
                            return app.getLable('未'+txt+'库','warning');
                        }else if( row.status == '21' ){
                            return app.getLable('部分'+txt+'库','warning');
                        }else if( row.status == '22' ){
                            return app.getLable('已'+txt+'库','success');
                        }else{
                            return app.getLable('状态异常','danger');
                        }
                    }},
                {field:'userName',title:'制单人',width:100,fixed:true}
            ]
        });
    });
</script>

</body>
</html>